# 396 中等：旋转函数

def maxRotateFunction(nums) -> int:

    # 超时
    # def F(n):
    #     sums = 0
    #     for i in range(len(nums)):
    #         sums += i * nums[(n + i) % len(nums)]
    #     return sums
    #
    # maxm = 0
    # for i in range(len(nums)):
    #     maxm = max(maxm, F(i))
    #
    # return maxm

    sums = sum(nums)
    f = [0] * len(nums)
    for i in range(len(nums)):
        f[0] += nums[i] * i
    for i in range(1, len(nums)):
        f[i] = f[i - 1] + sums - len(nums) * nums[len(nums) - i]
        # print(f[i])
    return max(f)


print(maxRotateFunction([4, 3, 2, 6]))
print(maxRotateFunction([100]))
